﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class StoredProcedures
    Shared Sub ShowError(ByRef ErrorMessage As String)
        Dim _oConn As New SqlConnection("context connection=true")

        Try
            Dim _sCmd As String
            Dim _oCmd As SqlCommand

            _oConn.Open()

            _sCmd = "RAISERROR('" _
                  & ErrorMessage.Replace("'", """") _
                  & "',16,1)"

            _oCmd = New SqlCommand(_sCmd, _oConn)

            SqlContext.Pipe.ExecuteAndSend(_oCmd)
        Catch ex As Exception
            SqlContext.Pipe.Send(ex.ToString)

            _oConn.Close()
        End Try
    End Sub

    Shared Sub ShowErrorConn(ByRef ErrorMessage As String, ByVal SQLConnectionObj As SqlConnection)
        Try
            If SQLConnectionObj.State <> ConnectionState.Open Then
                SQLConnectionObj.Open()
            End If

            Dim _sCmd As String
            Dim _oCmd As SqlCommand

            _sCmd = "RAISERROR('" _
                  & ErrorMessage.Replace("'", """") _
                  & "',16,1)"

            _oCmd = New SqlCommand(_sCmd, SQLConnectionObj)

            SqlContext.Pipe.ExecuteAndSend(_oCmd)
        Catch ex As Exception
            'Do nothing..  At least for now..
        End Try
    End Sub
End Class
